package com.yanqu.road.server.cmd.winery;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.winery.WineryProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.winery.WineryModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = GameProtocol.S_WINERY_CHOOSE_ONE_KEY_PAUSE_PATRON,desc = "酒肆一键饮酒")
public class WinerySetAutoPausePatronCmd extends AbstractCommand {

    private List<Integer> patronList;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WineryProto.WineryChooseOneKeyPausePatronReq req = WineryProto.WineryChooseOneKeyPausePatronReq.parseFrom(packet.getBytes());
        patronList = new ArrayList<>(req.getPatronIdList());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WineryModule.class).setAutoDrinkPausePatron(patronList);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            WineryProto.WineryChooseOneKeyPausePatronResp.Builder builder = WineryProto.WineryChooseOneKeyPausePatronResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_WINERY_CHOOSE_ONE_KEY_PAUSE_PATRON,builder);
        }
    }
}
